<template>
  <div class="wraper">
    <swiper :options="swiperOption" ref="mySwiper" v-if="List.length">
    <!-- slides -->
    <swiper-slide v-for="(page,index) of pages" :key="index">
      <div class="icons">
          <div class="icon" v-for="item of page" :key="item.id">
              <div class="icon-img">
                <img class="icon-img-content" :src="item.imgUrl" alt="">
              </div>
              <p class="icon-desc">{{item.desc}}</p>
          </div>
      </div>
    </swiper-slide>
   <!--  <swiper-slide>
      <img class="swiper_img" alt="">
    </swiper-slide> -->
    <!-- Optional controls -->
    <div class="swiper-pagination"  slot="pagination"></div>
  </swiper>
  </div>
</template>
<script>
export default {
  name: 'headerIcons',
  props: {
    List: Array
  },
  data: function () {
    return {
      swiperOption: {
        pagination: '.swiper-pagination',
        loop: true,
        autoplay: false
      }
    }
  },
  computed: {
    pages () {
      var pages = []
      // this.swiperList.forEach((item, index) => {
      //   const page = Math.floor(index / 8)
      //   if (!pages[page]) {
      //     pages[page] = []
      //   }
      //   pages[page].push(item)
      // })
      for (var i = 0; i < this.List.length; i++) {
        var page = Math.floor(i / 8)
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(this.List[i])
      }
      return pages
    }
  }
}
</script>
<style lang="stylus" scoped>
@import '~@/assets/styles/mixins.styl'
>>> .swiper-pagination-bullet-active {
 background: red;
}
.wraper {
 overflow: hidden;
  height: 0;
  padding-bottom: 50%;
  width: 100%;
overflow: hidden;
}
.icons {
  overflow: hidden;
  height: 0;
  padding-bottom: 50%;
  width: 100%;
overflow: hidden;
  background: none;
  display:flex;
  flex-wrap:wrap;
}
.icons .icon{
  width: 25%;
  padding-bottom:25%;
 position: relative;
overflow: hidden;
}
.icon-img{
  position:absolute;
  left:0;
  top:0;
  right:0;
  bottom:0.44 rem;
  padding:0.1 rem;
  box-sizing: border-box;
}
.icon .icon-img-content {
  display:block;
  height:100%;
  margin:0 auto;
}
.icon-desc{
  position: absolute;
        left: 0;
        right: 0;
        bottom: 0;
        height: .44 rem;
        line-height: .44 rem;
        text-align: center;
        ellipsis()
}
</style>
